package com.spsy.pay.controller;

import com.alibaba.fastjson2.JSON;
import com.spsy.common.core.domain.R;
import com.spsy.order.api.SpsyOrderProvider;
import com.spsy.pay.domain.Pay;
import com.spsy.pay.order.WeiXinUtil;
import com.spsy.pay.request.PayReq;
import com.spsy.pay.service.IPayService;
import com.spsy.pay.service.PayApiService;
import com.spsy.pay.vo.PayResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: liuzhiping
 * @date: 2024/12/12 15:25
 **/
@RestController
@RequestMapping("pay")
@Slf4j
public class PayApiController {


    @Autowired
    private SpsyOrderProvider spsyOrderProvider;

    @Autowired
    private PayApiService payApiService;


    @RequestMapping("notify222")
    public R testNotify(){

        System.out.println("----------------支付系统> notify开始2");
        //a1000004 白杨
        log.info("----------------支付系统> notify开始");


        spsyOrderProvider.notify("112121111",1);

        //更新数据库，更新支付状态

        return  R.ok();

    }


    //1：接受请求参数[其它系统调用支付接口的参数] ok

    //2: 保存数据表 pay

    //3: 构建参数【请求微信下单接口的参数】 ok
    //4：调用微信下单接口。 ok


    //5: 根据微信返回的结果，更新数据库

    //6: 获取二维码 ok
    //7: 返回前端 ok


    //手动postman下单
    @PostMapping("exec2")
    public R pay44(@RequestBody PayReq payReq) throws Exception{

        log.info("---payReq:{}", JSON.toJSONString(payReq));

        PayResult payResult = payApiService.pay(payReq.getOrderId());

        return  R.ok(payResult);

    }



    //order订单系统 发起的支付
    /*@PostMapping("orderExec")
    public R pay2232(@RequestParam(name = "orderId") String orderId) throws Exception{

        log.info("---orderId:{}", orderId);

        PayResult payResult = payApiService.pay(orderId);

        return  R.ok(payResult);

    }
*/


}
